package com.cnhis.cloudhealth.clinical.clidoctor.cliorderinvalid.bo;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cnhis.cloudhealth.clinical.clidoctor.clinewadvice.dao.CliNewAdviceDao;
import com.cnhis.cloudhealth.commons.Mappers.ModelVo;
import com.cnhis.cloudhealth.commons.utils.StaticKeys;

@Service
public class CliOrderInvalidBo {
	@Resource
	private CliNewAdviceDao cliNewAdviceDao;
	
	public ModelVo getclinicEditOrderBeforeJudge(Map map) throws Exception {
		
		ModelVo mo = new ModelVo(StaticKeys.OH_SUCCESS);
		
		//如果是非门诊，则返回成功
		if(!"1".equals(map.get("ACF01").toString())){
			return mo;
		}
		//是否有限制条件
		if(getBlp02(map)){
			return mo;
		}
		
		//获取限定年龄
		Integer BLP04 = getBlp04(map);
		
		//获取病人年龄
		Integer VAA10 = getVaa10(map);
		
		if((VAA10>=BLP04)&&getVcj04Vcj05(map)){
			mo.setResult(StaticKeys.OH_FALSE);
			mo.setResultMsg("病人超过"+BLP04+"岁，必须要输入收缩压和舒张压.");
			return mo;
		}
		
		return mo;
	}

	/**
	 * 入收缩压和舒张压 是否为空
	 * @param map
	 * @return
	 * @throws Exception 
	 */
	private boolean getVcj04Vcj05(Map map) throws Exception {
		int ct = cliNewAdviceDao.getVcj04Vcj05(map);
		if(ct>0){
			return true;
		}
		return false;
	}

	/**
	 * 获取病人年龄
	 * @param map
	 * @return
	 * @throws Exception 
	 */
	private Integer getVaa10(Map map) throws Exception {
		Integer VAA10 = cliNewAdviceDao.getVaa10(map);
		VAA10 = VAA10==null?0:VAA10;
		return VAA10;
	}

	/**
	 * 获取限定年龄
	 * @param map
	 * @return
	 * @throws Exception 
	 */
	private Integer getBlp04(Map map) throws Exception {
		Integer BLP04 = cliNewAdviceDao.getBlp04(map);
		BLP04 = BLP04==null?0:BLP04;
		return BLP04;
	}

	/**
	 * 是否有限制条件
	 * @param map
	 * @return
	 * @throws Exception
	 */
	private boolean getBlp02(Map map) throws Exception {
		int ct = cliNewAdviceDao.getBlp02(map);
		if(ct==0){
			return true;
		}
		return false;
	}
}
